var http=createRequestObject();
var uploader="";
var uploadDir="";
var dirname="";
var filename="";
var timeInterval="";
var idname="";
var uploaderId="";

function createRequestObject() {
    var obj;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
    	return new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
    	return new XMLHttpRequest();
    }   
}
function traceUpload() {
   http.onreadystatechange = handleResponse;
   http.open("GET", 'upload'); 
   http.send(null);
}
function handleResponse() {
	if(http.readyState == 4){
		var response=http.responseText; 
		if(http.status == 200){
			clearInterval(timeInterval);
			createHtml(response);
		}
        document.getElementById(uploaderId).innerHTML="<input size=\"1\" class=\"input\" id=\"id1\" name=\"id1\" type=\"file\" value=\"id1\" onchange='return uploadFile(this,\"\")' />";
    }
    else {
    	document.getElementById(uploaderId).innerHTML="Please wait...";
    }
}
function uploadFile(obj, dname) {
	uploadDir=obj.value;
	idname=obj.name;
	dirname=dname;
	//filename=uploadDir.substr(uploadDir.lastIndexOf('\\')+1);
	uploaderId = 'uploader'+obj.name;
	uploader = obj.name;
	document.getElementById('formName'+obj.name).submit();
	timeInterval=setInterval("traceUpload()", 1500);
}

function createHtml(msg){
	$("#request").before(msg);
}